﻿using UnityEngine;
using System.Collections;
using Memo.Electricity.Engine;
using UnityEngine.SceneManagement;

namespace Memo.Electricity.Test
{
	class Bg_Sprite : MemoBehaviour
	{

		public float mSpaceFactor;
		public float mTimeFactor;

		private Material material;
		private SpriteRenderer sr;

		private float camera_size;

		private float mTimeVal;

		private void Awake()
		{
			sr = GetComponent<SpriteRenderer>();
			material = sr.material;
			camera_size = Camera.main.orthographicSize;
		}

		private void Update()
		{
			mTimeVal += Time.deltaTime;

			//Offset
			Vector3 pos = Camera.main.transform.position;
			material.SetFloat("_Offset", pos.x * mSpaceFactor + mTimeVal * mTimeFactor);

			//Size;
			float size_scale = Camera.main.orthographicSize / camera_size;
			Vector3 scale = transform.localScale;
			scale.x = size_scale;
			scale.y = size_scale;
			transform.localScale = scale;

		}
	}
}
